/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 
 
 / / |                                                                                               M o m e n t u m   S c a l p e r   T E S T     
 
 / / |                                                                                                                             
 
 / / |                                                                                                                                                                                   
 
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 
 
 
 
 / /   D e s c r i p t i o n 
 
 / /   I n   t h i s   T E S T   v e r s i o n   t h e   s c r e e n   i s   p a i n t e d   i n   p a l e   g r e e n   w h e n   t h e   h i g h e r   T i m e f r a m e   
 
 / /   i s   p o s i t i v e ,   p i n k   w h e n   t h e   h i g h e r   T i m e f r a m e   i s   n e g a t i v e 
 
 / /   
 
 / /   
 
 / /   F u n c t i o n   S y m b o l ( ) ,   t h a t   i s   a n   M T 4   f u n c t i o n ,   i s   n o t   c a l l e d   t o   m a k e   t h e   i n d i 
 
 / /   u s a b l e   w i t h   G o l d   a n d   i n d i c e s   
 
 
 
 # p r o p e r t y   c o p y r i g h t   " " 
 
 
 
 # p r o p e r t y   i n d i c a t o r _ s e p a r a t e _ w i n d o w   
 
 
 
 # p r o p e r t y   i n d i c a t o r _ l e v e l 1         1 0 0       / /   A t t e n z i o n e   l i v e l l i   e   M o m e n t u m   s o n o   d i v e r s i 
 
 # p r o p e r t y   i n d i c a t o r _ l e v e l 2         - 1 0 0     / /   Q u e s t o      d a   c o n s i d e r a r s i   l i v e l l o   d i   O v e r S o l d   O v e r B o u g h t 
 
 / / # p r o p e r t y   i n d i c a t o r _ l e v e l 3         0 
 
 # p r o p e r t y   i n d i c a t o r _ l e v e l c o l o r       B l a c k 
 
 # p r o p e r t y   i n d i c a t o r _ l e v e l s t y l e       S T Y L E _ D O T 
 
 
 
 # p r o p e r t y   i n d i c a t o r _ b u f f e r s   5   
 
 # p r o p e r t y   i n d i c a t o r _ c o l o r 1         D i m G r a y 
 
 # p r o p e r t y   i n d i c a t o r _ c o l o r 2         B l u e 
 
 # p r o p e r t y   i n d i c a t o r _ c o l o r 3         O r a n g e 
 
 # p r o p e r t y   i n d i c a t o r _ c o l o r 4         R e d 
 
 # p r o p e r t y   i n d i c a t o r _ c o l o r 5         W h i t e 
 
 # p r o p e r t y   i n d i c a t o r _ s t y l e 1         S T Y L E _ S O L I D 
 
 # p r o p e r t y   i n d i c a t o r _ s t y l e 2         S T Y L E _ S O L I D 
 
 # p r o p e r t y   i n d i c a t o r _ s t y l e 3         S T Y L E _ S O L I D 
 
 # p r o p e r t y   i n d i c a t o r _ s t y l e 4         S T Y L E _ S O L I D 
 
 # p r o p e r t y   i n d i c a t o r _ s t y l e 5         S T Y L E _ S O L I D 
 
 # p r o p e r t y   i n d i c a t o r _ w i d t h 1         3 
 
 # p r o p e r t y   i n d i c a t o r _ w i d t h 2         3 
 
 # p r o p e r t y   i n d i c a t o r _ w i d t h 3         3 
 
 # p r o p e r t y   i n d i c a t o r _ w i d t h 4         3 
 
 # p r o p e r t y   i n d i c a t o r _ w i d t h 5         3 
 
 
 
 / / - - - -   i n p u t   p a r a m e t e r s 
 
 e x t e r n   s t r i n g   T i m e F r a m e   =   " c u r r e n t   t i m e   f r a m e " ; 
 
 e x t e r n   i n t               M o m e n t u m _ P e r i o d = 5 ; 
 
 e x t e r n   i n t               n u m _ b a r s = 1 0 0 0 ; 
 
 
 
 e x t e r n   i n t               m o m e n t u m = 1 0 0 ; 
 
 
 
 e x t e r n   s t r i n g         O v e r _ S _ B _ _ e q u a l s _ I n d i _ L e v e l s = " * * C o m m e n t * * " ; 
 
 e x t e r n   i n t               O v e r S o l d _ O v e r B o u g h t = 1 0 0 ; 
 
 
 
 e x t e r n   s t r i n g         C o l o r _ o f _ B a c k g r o u n d = " * * C o m m e n t * * " ;     / /   C h o o s e   b a c k g r o u n d   c o l o r   f o r   I n d i c a t o r   W i n d o w 
 
 e x t e r n   s t r i n g         o f _ h i g h e r _ T F = " * * C o m m e n t * * " ; 
 
 e x t e r n   b o o l             S h o w _ D i f f e r e n t _ B a c k g r o u n d = T R U E ; 
 
 e x t e r n   c o l o r           P o s i t i v e _ B a c k g r o u n d _ C o l o r = P a l e G r e e n ; 
 
 e x t e r n   c o l o r           N e g a t i v e _ B a c k g r o u n d _ C o l o r = P i n k ; 
 
 
 
 e x t e r n   s t r i n g         U s e _ t h i s _ t o _ s h o w _ B l u e _ H i s t o s = " * * C o m m e n t * * " ; 
 
 e x t e r n   s t r i n g         w h e n _ M o m e n t u m _ i s _ n o t _ r e a c h e d = " * * C o m m e n t * * " ; 
 
 e x t e r n   b o o l             A l w a y s _ S h o w _ P r i c e _ D i v e r g e n c e = F a l s e ; 
 
 
 
 e x t e r n   s t r i n g         D i f f e r e n t _ B a c k g r o u n d _ o n _ C h a r t = " * * C o m m e n t * * " ; 
 
 e x t e r n   b o o l             M a i n _ W i n d o w _ B a c k g r o u n d = T r u e ;     / /   U s e   t h i s   t o   p a i n t   M a i n   W i n d o w 
 
 
 
 / /   p a r a m e t e r s   
 
 b o o l   i n i t D o = t r u e ; 
 
 i n t   b a r = 0 ;   i n t   p r e v b a r s = 0 ;   i n t   s t a r t p a r = 0 ; 
 
 i n t   c s = 0 ;   i n t   p r e v c s = 0 ;   i n t   f r a m e = 0 ; 
 
 s t r i n g   c o m m o d t = " n o t h i n g " ; 
 
 
 
 s t r i n g   I n d i _ N a m e ; 
 
 
 
 b o o l   e x p i r e d = f a l s e ; 
 
 d o u b l e   n o w ,   p r e v ,   n o w _ h i g h ,   p r e v _ h i g h ,   n o w _ l o w ,   p r e v _ l o w ; 
 
 d o u b l e   M a x _ C C I = 0 ,   M a x _ H i g h   =   0 ,   M a x _ L o w   =   0 ; 
 
 
 
 i n t   T F 2 ;     / /      i l   T i m e f r a m e + 1 ,      v a r .   g l o b a l e   - - >   d e c i s a   i n   I N I T   e d   u s a t a   n e l   c i c l o   d i   T F + 1 
 
 d o u b l e   C C I _ T F 2 _ n o w ; 
 
 d o u b l e   C C I _ T F 2 _ p r e v ; 
 
 
 
 / /   v a r i a b i l i   g l o b a l i   u t i l i z z a t e   n e l   c i c l o   d i   T F   p i    a l t o   q u i   e   n e l l e   f u n z i o n i   " R e c t " 
 
 b o o l   N e w _ R e c t   =   F A L S E ; 	 b o o l   N e w _ R e c t _ n e g   =   F A L S E ; 
 
 d a t e t i m e   S t a r t _ R e c t _ T i m e ;       
 
 d a t e t i m e   S t a r t _ R e c t _ T i m e _ n e g ; 
 
 d a t e t i m e   E n d _ R e c t _ T i m e ;         
 
 d a t e t i m e   E n d _ R e c t _ T i m e _ n e g ; 
 
 
 
 
 
 / / - - - -   b u f f e r s 
 
 d o u b l e   H i s t o G r a y [ ] ;           / /   V a r i a b i l i   g l o b a l i 
 
 d o u b l e   H i s t o B l u e [ ] ;           / /   u s a t e   p e r   i   b u f f e r   d e i   d i v e r s i   t i p i   d i   H i s t o 
 
 d o u b l e   H i s t o O r a n g e [ ] ; 
 
 d o u b l e   H i s t o R e d [ ] ; 
 
 d o u b l e   H i s t o B l a c k [ ] ; 
 
 
 
 s t r i n g   i n d i c a t o r F i l e N a m e ; 
 
 b o o l       r e t u r n B a r s ; 
 
 i n t         t i m e F r a m e ; 
 
 
 
 
 
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 
 
 / / |   C u s t o m   i n d i c a t o r   i n i t i a l i z a t i o n   f u n c t i o n                                                   | 
 
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 
 
 i n t   i n i t ( ) 
 
     { 
 
       / /   I n d i c a t o r   N a m e   s h o w e d 
 
       
 
       
 
       / /   H A H 
 
       / /   i f   (   T i m e C u r r e n t ( )   >   S t r T o T i m e ( " 2 0 1 1 . 2 . 2 4   0 0 : 0 0 : 0 0 " )   & &   T i m e C u r r e n t ( )   <   S t r T o T i m e ( " 2 0 1 0 . 1 2 . 3 1   0 0 : 0 0 : 0 0 " )   )   
 
             / /   { 
 
             / /   A l e r t ( " C o n t a c t " ) ; 
 
             / /   A l e r t ( I n d i _ N a m e + "   I n d i c a t o r   i s   e x p i r i n g   i n   a   w e e k . " ) ; 
 
             / /   } 
 
       
 
       / /   i f   ( T i m e C u r r e n t ( )   >   S t r T o T i m e ( " 2 0 1 1 . 2 . 3 1   0 0 : 0 0 : 0 0 " ) )   
 
             / /   { 
 
             / /   A l e r t ( " C o n t a c t " ) ; 
 
             / /   A l e r t ( I n d i _ N a m e + " ) ; 
 
             / /   e x p i r e d   =   f a l s e ; 
 
             / /   r e t u r n   ( 0 ) ; 
 
             / /   } 
 
             
 
 / / - - - -   C C I   H i s t o   C o l o u r s 
 
       S e t I n d e x S t y l e ( 0 , D R A W _ H I S T O G R A M ) ; 
 
       S e t I n d e x B u f f e r ( 0 , H i s t o G r a y ) ; 
 
       
 
       S e t I n d e x S t y l e ( 1 , D R A W _ H I S T O G R A M ) ; 
 
       S e t I n d e x B u f f e r ( 1 , H i s t o B l u e ) ; 
 
       
 
       S e t I n d e x S t y l e ( 2 , D R A W _ H I S T O G R A M ) ; 
 
       S e t I n d e x B u f f e r ( 2 , H i s t o O r a n g e ) ; 
 
       
 
       S e t I n d e x S t y l e ( 3 , D R A W _ H I S T O G R A M ) ; 
 
       S e t I n d e x B u f f e r ( 3 , H i s t o R e d ) ; 
 
       
 
       S e t I n d e x S t y l e ( 4 , D R A W _ H I S T O G R A M ) ; 
 
       S e t I n d e x B u f f e r ( 4 , H i s t o B l a c k ) ; 
 
 
 
         t i m e F r a m e                   =   s t r i n g T o T i m e F r a m e ( T i m e F r a m e ) ; 
 
         i n d i c a t o r F i l e N a m e   =   W i n d o w E x p e r t N a m e ( ) ; 
 
         r e t u r n B a r s                 =   T i m e F r a m e   = =   " r e t u r n B a r s " ;   i f   ( r e t u r n B a r s )   r e t u r n ( 0 ) ; 
 
         I n d i _ N a m e                   =   " M o m e n t u m   S c a l p e r " ; 
 
         I n d i c a t o r S h o r t N a m e ( I n d i _ N a m e ) ; 
 
       r e t u r n ( 0 ) ; 
 
     } 
 
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 
 
 / / |   C u s t o m   i n d i c a t o r   d e i n i t i a l i z a t i o n   f u n c t i o n                                         
 
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 
 
 i n t   d e i n i t ( ) 
 
     { 
 
     / *     / /   n o n   m i   f u n z i o n a ,   a l c u n i   R e t t a n g o l i   n o n   v e n g o n o   c a n c e l l a t i 
 
     i n t   a = 0 ; 
 
     w h i l e   (   a   <   O b j e c t s T o t a l ( O B J _ R E C T A N G L E )   )   
 
                 { 
 
                 s t r i n g   n a m e   =   O b j e c t N a m e ( a ) ; 
 
                 i f   (   S t r i n g F i n d ( n a m e ,   I n d i _ N a m e ,   0 )   ! =   - 1   )   O b j e c t D e l e t e ( n a m e ) ; 
 
                 a + + ; 
 
                 }   
 
     * /       
 
     d e l e t e O b j e c t s ( ) ;     
 
     r e t u r n ( 0 ) ; 
 
     } 
 
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 
 
 / / |   C u s t o m   i n d i c a t o r   i t e r a t i o n   f u n c t i o n                                                         
 
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 
 
 v o i d   d e l e t e O b j e c t s ( s t r i n g   a d d = " " ) 
 
 { 
 
       s t r i n g   l o o k F o r               =   I n d i _ N a m e + a d d ; 
 
       i n t         l o o k F o r L e n g t h   =   S t r i n g L e n ( l o o k F o r ) ; 
 
       f o r   ( i n t   i = O b j e c t s T o t a l ( ) - 1 ;   i > = 0 ;   i - - ) 
 
       { 
 
             s t r i n g   n a m e   =   O b j e c t N a m e ( i ) ; 
 
             i f   ( S t r i n g S u b s t r ( n a m e , 0 , l o o k F o r L e n g t h ) = = l o o k F o r )   O b j e c t D e l e t e ( n a m e ) ; 
 
       } 
 
 } 
 
 
 
 i n t   s t a r t ( ) 
 
 { 
 
       i n t   c o u n t e d _ b a r s = I n d i c a t o r C o u n t e d ( ) ; 
 
             i f   ( c o u n t e d _ b a r s < 0 )   r e t u r n ( - 1 ) ; 
 
             i f   ( c o u n t e d _ b a r s > 0 )   c o u n t e d _ b a r s - - ; 
 
                   i n t   l i m i t   =   M a t h M i n ( B a r s - c o u n t e d _ b a r s , B a r s - 1 ) ; 
 
                   i f   ( r e t u r n B a r s )   {   H i s t o G r a y [ 0 ]   =   l i m i t + 1 ;   r e t u r n ( 0 ) ;   } 
 
                   i f   ( t i m e F r a m e ! = P e r i o d ( ) ) 
 
                   { 
 
                         l i m i t   =   M a t h M a x ( l i m i t , M a t h M i n ( B a r s - 1 , i C u s t o m ( N U L L , t i m e F r a m e , i n d i c a t o r F i l e N a m e , " r e t u r n B a r s " , 0 , 0 ) * t i m e F r a m e / P e r i o d ( ) ) ) ; 
 
                         f o r ( i n t   i = l i m i t ;   i > = 0 ;   i - - ) 
 
                         { 
 
                               i n t   y   =   i B a r S h i f t ( N U L L , t i m e F r a m e , T i m e [ i ] ) ;     
 
                                     H i s t o G r a y [ i ]       =   i C u s t o m ( N U L L , t i m e F r a m e , i n d i c a t o r F i l e N a m e , " c a l c u l a t e V a l u e " , M o m e n t u m _ P e r i o d , n u m _ b a r s , m o m e n t u m , " " , O v e r S o l d _ O v e r B o u g h t , " " , " " , S h o w _ D i f f e r e n t _ B a c k g r o u n d , P o s i t i v e _ B a c k g r o u n d _ C o l o r , N e g a t i v e _ B a c k g r o u n d _ C o l o r , " " , " " , A l w a y s _ S h o w _ P r i c e _ D i v e r g e n c e , " " , M a i n _ W i n d o w _ B a c k g r o u n d , 0 , y ) ;               
 
                                     H i s t o B l u e [ i ]       =   i C u s t o m ( N U L L , t i m e F r a m e , i n d i c a t o r F i l e N a m e , " c a l c u l a t e V a l u e " , M o m e n t u m _ P e r i o d , n u m _ b a r s , m o m e n t u m , " " , O v e r S o l d _ O v e r B o u g h t , " " , " " , S h o w _ D i f f e r e n t _ B a c k g r o u n d , P o s i t i v e _ B a c k g r o u n d _ C o l o r , N e g a t i v e _ B a c k g r o u n d _ C o l o r , " " , " " , A l w a y s _ S h o w _ P r i c e _ D i v e r g e n c e , " " , M a i n _ W i n d o w _ B a c k g r o u n d , 1 , y ) ;   
 
                                     H i s t o O r a n g e [ i ]   =   i C u s t o m ( N U L L , t i m e F r a m e , i n d i c a t o r F i l e N a m e , " c a l c u l a t e V a l u e " , M o m e n t u m _ P e r i o d , n u m _ b a r s , m o m e n t u m , " " , O v e r S o l d _ O v e r B o u g h t , " " , " " , S h o w _ D i f f e r e n t _ B a c k g r o u n d , P o s i t i v e _ B a c k g r o u n d _ C o l o r , N e g a t i v e _ B a c k g r o u n d _ C o l o r , " " , " " , A l w a y s _ S h o w _ P r i c e _ D i v e r g e n c e , " " , M a i n _ W i n d o w _ B a c k g r o u n d , 2 , y ) ;   
 
                                     H i s t o R e d [ i ]         =   i C u s t o m ( N U L L , t i m e F r a m e , i n d i c a t o r F i l e N a m e , " c a l c u l a t e V a l u e " , M o m e n t u m _ P e r i o d , n u m _ b a r s , m o m e n t u m , " " , O v e r S o l d _ O v e r B o u g h t , " " , " " , S h o w _ D i f f e r e n t _ B a c k g r o u n d , P o s i t i v e _ B a c k g r o u n d _ C o l o r , N e g a t i v e _ B a c k g r o u n d _ C o l o r , " " , " " , A l w a y s _ S h o w _ P r i c e _ D i v e r g e n c e , " " , M a i n _ W i n d o w _ B a c k g r o u n d , 3 , y ) ; 
 
                                     H i s t o B l a c k [ i ]     =   i C u s t o m ( N U L L , t i m e F r a m e , i n d i c a t o r F i l e N a m e , " c a l c u l a t e V a l u e " , M o m e n t u m _ P e r i o d , n u m _ b a r s , m o m e n t u m , " " , O v e r S o l d _ O v e r B o u g h t , " " , " " , S h o w _ D i f f e r e n t _ B a c k g r o u n d , P o s i t i v e _ B a c k g r o u n d _ C o l o r , N e g a t i v e _ B a c k g r o u n d _ C o l o r , " " , " " , A l w a y s _ S h o w _ P r i c e _ D i v e r g e n c e , " " , M a i n _ W i n d o w _ B a c k g r o u n d , 4 , y ) ;                                                                                             
 
                         }   
 
                   r e t u r n ( 0 ) ; 
 
                   } 
 
       
 
       / /   i f   ( e x p i r e d )   r e t u r n   ( 0 ) ;   
 
         
 
       / /   C H E C K 
 
       c o u n t e d _ b a r s = I n d i c a t o r C o u n t e d ( ) ; 
 
 
 
       c s   =   M o m e n t u m _ P e r i o d   +   n u m _ b a r s ;   / / c h e c k s u m   u s e d   t o   s e e   i f   p a r a m e t e r s   h a v e   b e e n   c h a n g e d 
 
 
 
       i f   ( ( c s = = p r e v c s )   & &   	 	 	 	 	 	 	 	 / /   & &   ( c o m m o d t   = =   S y m b o l ( ) )   e r a s e d   
 
             ( f r a m e   = =   ( T i m e [ 4 ]   -   T i m e [ 5 ] ) )   & & 
 
             ( ( B a r s   -   p r e v b a r s )   <   2 ) ) 
 
             s t a r t p a r   =   B a r s   -   p r e v b a r s ;   
 
       e l s e   
 
             s t a r t p a r   =   - 1 ;     / / p a r a m s   h a v e n ' t   c h a n g e d   o n l y   n e e d   t o   c a l c u l a t e   n e w   b a r 
 
 
 
       / / c o m m o d t   =   S y m b o l ( ) ; 
 
       f r a m e   =   T i m e [ 4 ]   -   T i m e [ 5 ] ; 
 
       p r e v b a r s   =   B a r s ; 
 
       p r e v c s   =   c s ; 
 
 
 
       i f   ( s t a r t p a r   = =   1   | |   s t a r t p a r   = =   0 )     
 
             b a r   =   s t a r t p a r ; 
 
       e l s e   
 
             i n i t D o   =   t r u e ;       
 
       / /   E N D   C H E C K :   i f   c h e c k   O K ,   B A R   =   0 ,   c y c l e   " F O R "   o n l y   o f   t h e   l a s t   b a r 
 
 
 
 
 
       / /   I n   c a s e   o f   f i r s t   t i c k   o r   c h e c k s u m   e r r o r 
 
       / /   i n i t i a l i z e   b u f f e r s   a n d   d o   a l l   t h e   " N u m B a r s "   i n   " F O R "   c y c l e   
 
       i f   ( i n i t D o )   
 
             { 
 
             H i s t o G r a y [ n u m _ b a r s - 1 ] = 0 ; 
 
             H i s t o B l u e [ n u m _ b a r s - 1 ] = 0 ; 
 
             H i s t o O r a n g e [ n u m _ b a r s - 1 ] = 0 ; 
 
             H i s t o R e d [ n u m _ b a r s - 1 ] = 0 ; 
 
             b a r = n u m _ b a r s - 2 ; 
 
             i n i t D o = f a l s e ; 
 
             
 
             i n t   w i n d o w = W i n d o w F i n d ( I n d i _ N a m e ) ;                       / /   c a n c e l l i a m o   i   v e c c h i   R e t t a n g o l i   
 
             O b j e c t s D e l e t e A l l ( w i n d o w , O B J _ R E C T A N G L E ) ;           / /   ( e s .   s e   c a m b i a m o   T F ) 
 
             
 
             O b j e c t s D e l e t e A l l ( 0 , O B J _ R E C T A N G L E ) ;                       / /   c a n c e l l i a m o   i   v e c c h i   R e t t a n g o l i   n e l l a   C h a r t   W i n d o w 
 
             } 
 
               
 
                     
 
       / /   C o r e   F u n c t i o n   S t a r t   ( F O R ) 
 
       f o r   ( i   =   b a r ;   i   > =   0 ;   i - - )   
 
       {       
 
             / /   a l l   t h e   b u f f e r s   t o   z e r o   t o   a v o i d 
 
             / /   o v e r l a p   o f   h i s t o s   ( l a s t   h i s t o   e r a s e d ) 
 
             H i s t o G r a y [ i ]   =   E M P T Y _ V A L U E ; 
 
             H i s t o B l u e [ i ]   =   E M P T Y _ V A L U E ; 
 
             H i s t o O r a n g e [ i ]   =   E M P T Y _ V A L U E ; 
 
             H i s t o R e d [ i ]   =   E M P T Y _ V A L U E ; 
 
             H i s t o B l a c k [ i ]   =   E M P T Y _ V A L U E ; 
 
             
 
             b o o l   c h a n g e _ o f _ s i g n   =   F A L S E ; 
 
             
 
             n o w   =   i C C I ( N U L L , 0 , M o m e n t u m _ P e r i o d , P R I C E _ T Y P I C A L , i ) ; 
 
             p r e v   =   i C C I ( N U L L , 0 , M o m e n t u m _ P e r i o d , P R I C E _ T Y P I C A L , i + 1 ) ; 
 
             n o w _ h i g h   =   i H i g h ( N U L L , 0 , i ) ; 
 
             p r e v _ h i g h   =   i H i g h ( N U L L , 0 , i + 1 ) ; 
 
             n o w _ l o w   =   i L o w ( N U L L , 0 , i ) ; 
 
             p r e v _ l o w   =   i L o w ( N U L L , 0 , i + 1 ) ; 
 
             
 
             / /   c h a n g e   o f   s i g n   = >   M a x _ C C I   a n d   M a x _ P r i c e   t o   z e r o   ( f i r s t   C C I   R e d ) 
 
             i f   ( ( p r e v   > =   0   & &   n o w   <   0 )   | |   ( p r e v   < =   0   & &   n o w   >   0 ) )   
 
                     { M a x _ C C I   =   0 ;   c h a n g e _ o f _ s i g n   =   T R U E ; 
 
                     M a x _ H i g h   =   0 ;   M a x _ L o w   =   1 2 3 4 5 6 7 8 9 ; }   
 
             
 
             / /   U p d a t e   M a x   a t   e n d   o f   b a r   - -   o g n i   c o n f r o n t o 
 
             / /   v i e n e   e f f e t t u a t o   s u l l a   b a r r a   p r e c e d e n t e   
 
             i f   (   M a t h A b s ( p r e v ) > M a t h A b s ( M a x _ C C I )   )   M a x _ C C I   =   p r e v ;   
 
             i f   ( n o w   > = 0 )   { i f   ( p r e v _ h i g h   >   M a x _ H i g h )   M a x _ H i g h   =   p r e v _ h i g h ; } 
 
             i f   ( n o w   < = 0 )   { i f   ( p r e v _ l o w   <   M a x _ L o w )   M a x _ L o w   =   p r e v _ l o w ; } 
 
                               
 
             / /   C o l o u r   i t !             
 
             i f   ( n o w   > =   m o m e n t u m ) 
 
                   { 
 
                   i f   (   n o w > p r e v   & &   n o w > = M a x _ C C I   )   H i s t o R e d [ i ]   =   n o w ;     / / n o w > p r e v   - -   u t i l e ? 
 
                   i f   (   n o w < M a x _ C C I   & &   n o w _ h i g h > = M a x _ H i g h   )   H i s t o B l u e [ i ]   =   n o w ;   / /   * * D i v e r g e n c e   ! ! * * 
 
                   i f   (   n o w _ h i g h < M a x _ H i g h   )   H i s t o O r a n g e [ i ]   =   n o w ; 
 
                   i f   ( c h a n g e _ o f _ s i g n )   H i s t o B l a c k [ i ]   =   m o m e n t u m ;     / /   H i s o B l a c k   ( h i s t o   p i    c o r t o ) 
 
                   }                                                                                             / /   r i d i s e g n a t o   s o p r a   a d   H i s t o   c o l o r a t o 
 
 
 
             i f   ( n o w   < =   - m o m e n t u m ) 
 
                   { 
 
                   i f   (   n o w < p r e v   & &   n o w < = M a x _ C C I   )   H i s t o R e d [ i ]   =   n o w ; 
 
                   i f   (   n o w > M a x _ C C I   & &   n o w _ l o w < = M a x _ L o w   )   H i s t o B l u e [ i ]   =   n o w ;   / /   * * D i v e r g e n c e   ! ! * * 
 
                   i f   (   n o w _ l o w > M a x _ L o w   )   H i s t o O r a n g e [ i ]   =   n o w ; 
 
                   i f   ( c h a n g e _ o f _ s i g n )   H i s t o B l a c k [ i ]   =   - m o m e n t u m ; 
 
                   } 
 
             
 
             i f   ( n o w   >   - m o m e n t u m   & &   n o w   <   m o m e n t u m )   
 
                   { 
 
                   i f   ( c h a n g e _ o f _ s i g n )   H i s t o B l a c k [ i ]   =   n o w ;   
 
                         e l s e   
 
                               { 
 
                               H i s t o G r a y [ i ]   =   n o w ; 
 
                               i f   ( A l w a y s _ S h o w _ P r i c e _ D i v e r g e n c e ) 
 
                                     { 
 
                                     i f   (   n o w > 0   & &   n o w < M a x _ C C I   & &   n o w _ h i g h > = M a x _ H i g h   )   H i s t o B l u e [ i ]   =   n o w ;   / /   * * D i v e r g e n c e   ! ! * * 
 
                                     i f   (   n o w < 0   & &   n o w > M a x _ C C I   & &   n o w _ l o w < = M a x _ L o w   )   H i s t o B l u e [ i ]   =   n o w ;   / /   * * D i v e r g e n c e   ! ! * * 
 
                                     } 
 
                               } 
 
                   } 
 
             
 
       
 
       / / * * * * * * * * * * * * * * * *   c i c l o   s u   T i m e f r a m e   p i    a l t o   p e r   c o l o r a r e   l o   s f o n d o 
 
       / / * * * * * * * * * * * * * * * *   s f o n d o   n o r m a l m e n t e   d i   u n   c o l o r e   ( g r i g i o   p e r   m e ) 
 
       / / * * * * * * * * * * * * * * * *   v i e n e   c o l o r a t o   c o n   i l   c o l o r e   " P o s i t i v e _ B a c k g r o u n d   C o l o r " 
 
       / / * * * * * * * * * * * * * * * *   q u a n d o   i l   T F   p i    a l t o      p o s i t i v o 
 
       / / * * * * * * * * * * * * * * * *   m e n t r e      c o l o r a t o   c o n   i l   c o l o r e   " N e g a t i v e _ B a c k g r o u n d   C o l o r " 
 
       / / * * * * * * * * * * * * * * * *   q u a n d o   i l   T F   p i    a l t o      n e g a t i v o 
 
       
 
       i f   ( S h o w _ D i f f e r e n t _ B a c k g r o u n d ) 
 
             { 
 
             
 
             i n t   T F   =   P e r i o d   ( ) ;   / / s u   q u a l e   T F   s t i a m o ? 
 
             
 
             / /   m i   s p o s t o   s u   T F + 1 
 
             i n t   T i m e F r a m e _ A r r a y [ ]   =   { 1 ,   5 ,   1 5 ,   3 0 ,   6 0 ,   2 4 0 ,   1 4 4 0 ,   1 0 0 8 0 ,   4 3 2 0 0 } ; 
 
             i n t   a = 0 ; 
 
             w h i l e   ( a < = 8 ) 
 
                         {   
 
                         i f   ( T F = = T i m e F r a m e _ A r r a y [ a ] )   T F 2 = T i m e F r a m e _ A r r a y [ a + 1 ] ;     
 
                         a + + ; 
 
                         } 
 
                         
 
             / /   m i   s p o s t o   s u   T F + 1       
 
             
 
             i n t   s h i f t   =   T F 2 * 6 0 ;   / /   s h i f t   i n   s e c o n d i   p e r   E n d _ R e c t 
 
             i n t   s h i f t _ a c t u a l   =   T F * 6 0 ;     / /   L a   f u n z i o n e   i T i m e   n o n   r e s t i t u i s c e   T I M E   d i   b a r r a   n o n   e s i s t e n t i :   i - 1   q u a n d o   i = 0 
 
       
 
             C C I _ T F 2 _ n o w   =   i C C I ( N U L L , T F 2 , M o m e n t u m _ P e r i o d , P R I C E _ T Y P I C A L , i ) ; 
 
             C C I _ T F 2 _ p r e v   =   i C C I ( N U L L , T F 2 , M o m e n t u m _ P e r i o d , P R I C E _ T Y P I C A L , i + 1 ) ; 
 
             
 
             
 
 	     / /     * * * * *   H i g h e r   T F   >   0   ? ?   * * * * * 
 
             i f   ( i ! = 0 )     / /   l a v o r i a m o   s u   h i s t o r i c a l   b a r 
 
                   {                                                                         
 
                   i f   ( C C I _ T F 2 _ n o w > 0   & &   C C I _ T F 2 _ p r e v < = 0 )     / / C C I   T F 2   d i v e n t a   p o s i t i v o 
 
                           {   N e w _ R e c t = T R U E ;   S t a r t _ R e c t _ T i m e = i T i m e ( N U L L , T F 2 , i ) ;   E n d _ R e c t _ T i m e = i T i m e ( N U L L , T F 2 , i ) + s h i f t ;   D r a w _ R e c t ( ) ; }   
 
                                                                 / /   R e t t a n g o l o   c h e   t e r m i n a   u n a   b a r r a   p i    a v a n t i   
 
                                                                 / /   c o s I     v i s i b i l e   a n c h e   a l l a   p r i m a   b a r r a 
 
                   i f   ( N e w _ R e c t   & &   C C I _ T F 2 _ n o w > 0 )   {   E n d _ R e c t _ T i m e =   i T i m e ( N U L L , T F 2 , i ) + s h i f t ;   M o v e _ R e c t ( ) ;   } 
 
                   i f   ( C C I _ T F 2 _ n o w < = 0 )   N e w _ R e c t   =   F A L S E ;   
 
                   } 
 
               
 
                   e l s e   {             / /   i = 0   l a v o r i a m o   s u   b a r r a   a t t u a l e :   m u o v i a m o   R e c t   s u   T F   a t t u a l e 
 
                             i f   ( N e w _ R e c t   & &   C C I _ T F 2 _ n o w > 0 )   {   E n d _ R e c t _ T i m e = i T i m e ( N U L L , T F , i ) + s h i f t _ a c t u a l ;   M o v e _ R e c t ( ) ;   }   / / C C I   T F 2   g i    p o s i t i v o 
 
                             i f   ( ! N e w _ R e c t   & &   C C I _ T F 2 _ n o w > 0   & &   C C I _ T F 2 _ p r e v < = 0 )     / / C C I   T F 2   d i v e n t a   p o s i t i v o 
 
                                     {   N e w _ R e c t   =   T R U E ;   S t a r t _ R e c t _ T i m e = i T i m e ( N U L L , T F , i ) ;   E n d _ R e c t _ T i m e = i T i m e ( N U L L , T F , i ) + s h i f t _ a c t u a l ;   D r a w _ R e c t ( ) ; }   
 
                             i f   ( C C I _ T F 2 _ n o w < = 0 )   N e w _ R e c t   =   F A L S E ; 
 
                             } 
 
           
 
 
 
 	     / /     * * * * *   H i g h e r   T F   <   0   ? ?   * * * * * 
 
             i f   ( i ! = 0 )     / /   l a v o r i a m o   s u   h i s t o r i c a l   b a r 
 
                   {                                                                         
 
                   i f   ( C C I _ T F 2 _ n o w < 0   & &   C C I _ T F 2 _ p r e v > = 0 )     / / C C I   T F 2   d i v e n t a   n e g a t i v o 
 
                           {   N e w _ R e c t _ n e g = T R U E ;   S t a r t _ R e c t _ T i m e _ n e g = i T i m e ( N U L L , T F 2 , i ) ;   E n d _ R e c t _ T i m e _ n e g = i T i m e ( N U L L , T F 2 , i ) + s h i f t ;   D r a w _ R e c t _ n e g ( ) ; }   
 
                                                                 / /   R e t t a n g o l o   c h e   t e r m i n a   u n a   b a r r a   p i    a v a n t i   
 
                                                                 / /   c o s I     v i s i b i l e   a n c h e   a l l a   p r i m a   b a r r a 
 
                   i f   ( N e w _ R e c t _ n e g   & &   C C I _ T F 2 _ n o w < 0 )   {   E n d _ R e c t _ T i m e _ n e g =   i T i m e ( N U L L , T F 2 , i ) + s h i f t ;   M o v e _ R e c t _ n e g ( ) ;   } 
 
                   i f   ( C C I _ T F 2 _ n o w > = 0 )   N e w _ R e c t _ n e g   =   F A L S E ;   
 
                   } 
 
               
 
                   e l s e   {             / /   i = 0   l a v o r i a m o   s u   b a r r a   a t t u a l e :   m u o v i a m o   R e c t   s u   T F   a t t u a l e 
 
                             i f   ( N e w _ R e c t _ n e g   & &   C C I _ T F 2 _ n o w < 0 )   {   E n d _ R e c t _ T i m e _ n e g = i T i m e ( N U L L , T F , i ) + s h i f t _ a c t u a l ;   M o v e _ R e c t _ n e g ( ) ;   }   / / C C I   T F 2   g i    n e g a t i v o 
 
                             i f   ( ! N e w _ R e c t _ n e g   & &   C C I _ T F 2 _ n o w < 0   & &   C C I _ T F 2 _ p r e v > = 0 )     / / C C I   T F 2   d i v e n t a   n e g a t i v o 
 
                                     {   N e w _ R e c t _ n e g   =   T R U E ;   S t a r t _ R e c t _ T i m e _ n e g = i T i m e ( N U L L , T F , i ) ;   E n d _ R e c t _ T i m e _ n e g = i T i m e ( N U L L , T F , i ) + s h i f t _ a c t u a l ;   D r a w _ R e c t _ n e g ( ) ; }   
 
                             i f   ( C C I _ T F 2 _ n o w > = 0 )   N e w _ R e c t _ n e g   =   F A L S E ; 
 
                             } 
 
 	 	 	     
 
             }   / / E N D   I F   S h o w _ D i f f e r e n t _ B a c k g r o u n d 
 
 
 
       
 
       }   / /   E N D   F O R 
 
       r e t u r n ( 0 ) ; 
 
     }     / /   E N D   S T A R T 
 
     
 
     
 
     
 
 / / * * * * * * * * *   F U N Z I O N I   * * * * * * * * * * * * * * 
 
 
 
 v o i d   D r a w _ R e c t ( ) 
 
           { 
 
           s t r i n g   S t a r t _ R e c t _ S t r i n g   =   T i m e T o S t r   ( S t a r t _ R e c t _ T i m e ) ;   
 
           s t r i n g   n a m e   =   I n d i _ N a m e + "   " + S t a r t _ R e c t _ S t r i n g ; 
 
           i n t   w i n d o w = W i n d o w F i n d ( I n d i _ N a m e ) ;   
 
           O b j e c t C r e a t e ( n a m e ,   O B J _ R E C T A N G L E ,   w i n d o w ,   S t a r t _ R e c t _ T i m e ,   8 0 0 0 ,   E n d _ R e c t _ T i m e ,   - 8 0 0 0 ) ; 
 
           O b j e c t S e t ( n a m e ,   O B J P R O P _ C O L O R ,   P o s i t i v e _ B a c k g r o u n d _ C o l o r ) ; 
 
           O b j e c t S e t ( n a m e ,   O B J P R O P _ B A C K ,   T R U E ) ; 
 
           
 
           i f   ( M a i n _ W i n d o w _ B a c k g r o u n d )     / /   D r a w   t h e   s a m e   R e c t   o n   M a i n   W i n d o w   ( C h a r t   W i n d o w ) 
 
                   { 
 
                   n a m e   =   I n d i _ N a m e + "   M a i n   " + S t a r t _ R e c t _ S t r i n g ; 
 
                   O b j e c t C r e a t e ( n a m e ,   O B J _ R E C T A N G L E ,   0 ,   S t a r t _ R e c t _ T i m e ,   8 0 0 0 ,   E n d _ R e c t _ T i m e ,   - 8 0 0 0 ) ; 
 
                   O b j e c t S e t ( n a m e ,   O B J P R O P _ C O L O R ,   P o s i t i v e _ B a c k g r o u n d _ C o l o r ) ; 
 
                   O b j e c t S e t ( n a m e ,   O B J P R O P _ B A C K ,   T R U E ) ; 
 
                   } 
 
           } 
 
 
 
 v o i d   D r a w _ R e c t _ n e g ( ) 
 
           { 
 
           s t r i n g   S t a r t _ R e c t _ S t r i n g   =   T i m e T o S t r   ( S t a r t _ R e c t _ T i m e _ n e g ) ;   
 
           s t r i n g   n a m e   =   I n d i _ N a m e + "   " + S t a r t _ R e c t _ S t r i n g ; 
 
           i n t   w i n d o w = W i n d o w F i n d ( I n d i _ N a m e ) ;   
 
           O b j e c t C r e a t e ( n a m e ,   O B J _ R E C T A N G L E ,   w i n d o w ,   S t a r t _ R e c t _ T i m e _ n e g ,   8 0 0 0 ,   E n d _ R e c t _ T i m e _ n e g ,   - 8 0 0 0 ) ; 
 
           O b j e c t S e t ( n a m e ,   O B J P R O P _ C O L O R ,   N e g a t i v e _ B a c k g r o u n d _ C o l o r ) ; 
 
           O b j e c t S e t ( n a m e ,   O B J P R O P _ B A C K ,   T R U E ) ; 
 
           
 
           i f   ( M a i n _ W i n d o w _ B a c k g r o u n d )     / /   D r a w   t h e   s a m e   R e c t   o n   M a i n   W i n d o w   ( C h a r t   W i n d o w ) 
 
                   { 
 
                   n a m e   =   I n d i _ N a m e + "   M a i n   " + S t a r t _ R e c t _ S t r i n g ; 
 
                   O b j e c t C r e a t e ( n a m e ,   O B J _ R E C T A N G L E ,   0 ,   S t a r t _ R e c t _ T i m e _ n e g ,   8 0 0 0 ,   E n d _ R e c t _ T i m e _ n e g ,   - 8 0 0 0 ) ; 
 
                   O b j e c t S e t ( n a m e ,   O B J P R O P _ C O L O R ,   N e g a t i v e _ B a c k g r o u n d _ C o l o r ) ; 
 
                   O b j e c t S e t ( n a m e ,   O B J P R O P _ B A C K ,   T R U E ) ; 
 
                   } 
 
           } 
 
           
 
 v o i d   M o v e _ R e c t ( ) 
 
           { 
 
           s t r i n g   S t a r t _ R e c t _ S t r i n g   =   T i m e T o S t r   ( S t a r t _ R e c t _ T i m e ) ;   
 
           s t r i n g   n a m e   =   I n d i _ N a m e + "   " + S t a r t _ R e c t _ S t r i n g ; 
 
           O b j e c t M o v e ( n a m e ,   1 ,   E n d _ R e c t _ T i m e ,   - 8 0 0 0 ) ;     / /   S p o s t o   l a   c o o r d i n a t a   2   d e l l ' o g g e t t o   
 
           
 
           i f   ( M a i n _ W i n d o w _ B a c k g r o u n d )     
 
                   { 
 
                   n a m e   =   I n d i _ N a m e + "   M a i n   " + S t a r t _ R e c t _ S t r i n g ; 
 
                   O b j e c t M o v e ( n a m e ,   1 ,   E n d _ R e c t _ T i m e ,   - 8 0 0 0 ) ; 
 
                   } 
 
           } 
 
 
 
 v o i d   M o v e _ R e c t _ n e g ( ) 
 
           { 
 
           s t r i n g   S t a r t _ R e c t _ S t r i n g   =   T i m e T o S t r   ( S t a r t _ R e c t _ T i m e _ n e g ) ;   
 
           s t r i n g   n a m e   =   I n d i _ N a m e + "   " + S t a r t _ R e c t _ S t r i n g ; 
 
           O b j e c t M o v e ( n a m e ,   1 ,   E n d _ R e c t _ T i m e _ n e g ,   - 8 0 0 0 ) ;     / /   S p o s t o   l a   c o o r d i n a t a   2   d e l l ' o g g e t t o   
 
           
 
           i f   ( M a i n _ W i n d o w _ B a c k g r o u n d )     
 
                   { 
 
                   n a m e   =   I n d i _ N a m e + "   M a i n   " + S t a r t _ R e c t _ S t r i n g ; 
 
                   O b j e c t M o v e ( n a m e ,   1 ,   E n d _ R e c t _ T i m e _ n e g ,   - 8 0 0 0 ) ; 
 
                   } 
 
           } 
 
 
 
 / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 / / 
 
 / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 / / 
 
 / / 
 
 / / 
 
 / / 
 
 / / 
 
 
 
 s t r i n g   s T f T a b l e [ ]   =   { " M 1 " , " M 5 " , " M 1 0 " , " M 1 5 " , " M 3 0 " , " H 1 " , " H 4 " , " D 1 " , " W 1 " , " M N " } ; 
 
 i n t         i T f T a b l e [ ]   =   { 1 , 5 , 1 0 , 1 5 , 3 0 , 6 0 , 2 4 0 , 1 4 4 0 , 1 0 0 8 0 , 4 3 2 0 0 } ; 
 
 
 
 / / 
 
 / / 
 
 / / 
 
 / / 
 
 / / 
 
 
 
 i n t   s t r i n g T o T i m e F r a m e ( s t r i n g   t f s ) 
 
 { 
 
       t f s   =   s t r i n g U p p e r C a s e ( t f s ) ; 
 
       f o r   ( i n t   i = A r r a y S i z e ( i T f T a b l e ) - 1 ;   i > = 0 ;   i - - ) 
 
                   i f   ( t f s = = s T f T a b l e [ i ]   | |   t f s = = " " + i T f T a b l e [ i ] )   r e t u r n ( M a t h M a x ( i T f T a b l e [ i ] , P e r i o d ( ) ) ) ; 
 
                                                                                                             r e t u r n ( P e r i o d ( ) ) ; 
 
 } 
 
 s t r i n g   t i m e F r a m e T o S t r i n g ( i n t   t f ) 
 
 { 
 
       f o r   ( i n t   i = A r r a y S i z e ( i T f T a b l e ) - 1 ;   i > = 0 ;   i - - )   
 
                   i f   ( t f = = i T f T a b l e [ i ] )   r e t u r n ( s T f T a b l e [ i ] ) ; 
 
                                                             r e t u r n ( " " ) ; 
 
 } 
 
 
 
 / / 
 
 / / 
 
 / / 
 
 / / 
 
 / / 
 
 
 
 s t r i n g   s t r i n g U p p e r C a s e ( s t r i n g   s t r ) 
 
 { 
 
       s t r i n g       t s   =   s t r ; 
 
 
 
       f o r   ( i n t   l e n g t h = S t r i n g L e n ( s t r ) - 1 ;   l e n g t h > = 0 ;   l e n g t h - - ) 
 
       { 
 
             i n t   t c h a r   =   S t r i n g G e t C h a r ( t s ,   l e n g t h ) ; 
 
                   i f ( ( t c h a r   >   9 6   & &   t c h a r   <   1 2 3 )   | |   ( t c h a r   >   2 2 3   & &   t c h a r   <   2 5 6 ) ) 
 
                                           t s   =   S t r i n g S e t C h a r ( t s ,   l e n g t h ,   t c h a r   -   3 2 ) ; 
 
                   e l s e   i f ( t c h a r   >   - 3 3   & &   t c h a r   <   0 ) 
 
                                           t s   =   S t r i n g S e t C h a r ( t s ,   l e n g t h ,   t c h a r   +   2 2 4 ) ; 
 
       } 
 
       r e t u r n ( t s ) ; 
 
 } 
 
 